package lab03.Test12;

import java.sql.*;

/**
 * Created by 邱雅婷 on 2017/12/13.
 */
public class test {

        public static void main(String[] args) {

            Connection connection = null;
            Statement statement = null;
            ResultSet resultSet = null;

            String sql1 = "select * FROM t_users";
            String sql2 = "select * FROM t_users where username='admin'";
            String sql3 = "select * from t_users where username='admin' and password='123456'";
            String sql4 = "select * from t_users where register_datetime>1000000";
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                connection = DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                        "root",
                        "1234568"
                );
                statement = connection.createStatement();
                resultSet = statement.executeQuery(sql1);
                resultSet = statement.executeQuery(sql2);
                resultSet = statement.executeQuery(sql3);
                resultSet = statement.executeQuery(sql4);
                while (resultSet.next()) {
                    System.out.println(resultSet.getString(1) + " "
                            + resultSet.getString(2) + " "
                            + resultSet.getString(3) + " "
                            + resultSet.getString(4));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }finally {
                try {
                    connection.close();
                    statement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }


